package com.lyc.speechtranscriber.bean;

import android.content.Intent;
import android.media.projection.MediaProjection;
import android.media.projection.MediaProjectionManager;

import androidx.annotation.NonNull;

public class MediaProjectionProvider {

    private final int mPermissionCode;
    private final Intent mPermissionData;
    private final MediaProjectionManager mediaProjectionManager;

    private MediaProjection mMediaProjection;

    public MediaProjectionProvider(MediaProjectionManager mp, int code, Intent data){
        mediaProjectionManager = mp;
        mPermissionCode = code;
        mPermissionData = data;
    }

    @NonNull
    public synchronized MediaProjection getMediaProjection(){
        if (mMediaProjection == null){
            mMediaProjection = mediaProjectionManager.getMediaProjection(mPermissionCode,mPermissionData);
        }
        return mMediaProjection;
    }

    public int getPermissionCode(){
        return mPermissionCode;
    }

    public Intent getPermissionData(){
        return mPermissionData;
    }

    public void releaseMediaProjection(){
        if (mMediaProjection == null)
            return;
        mMediaProjection.stop();
        mMediaProjection = null;
    }

}
